from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-07-26 14:03:03.016663
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Tue, 26, Jul, 2022
Time: 14:03:10
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -49.9276
Nobs: 729.000 HQIC: -50.2757
Log likelihood: 9185.57 FPE: 1.17637e-22
AIC: -50.4945 Det(Omega_mle): 1.04062e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.299482 0.056749 5.277 0.000
L1.Burgenland 0.107368 0.037190 2.887 0.004
L1.Kärnten -0.106996 0.019725 -5.424 0.000
L1.Niederösterreich 0.207087 0.077887 2.659 0.008
L1.Oberösterreich 0.107024 0.075943 1.409 0.159
L1.Salzburg 0.254029 0.039793 6.384 0.000
L1.Steiermark 0.042886 0.051922 0.826 0.409
L1.Tirol 0.108679 0.042111 2.581 0.010
L1.Vorarlberg -0.062699 0.036315 -1.727 0.084
L1.Wien 0.048260 0.067182 0.718 0.473
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.054686 0.118507 0.461 0.644
L1.Burgenland -0.031723 0.077663 -0.408 0.683
L1.Kärnten 0.047113 0.041192 1.144 0.253
L1.Niederösterreich -0.178244 0.162649 -1.096 0.273
L1.Oberösterreich 0.409354 0.158590 2.581 0.010
L1.Salzburg 0.288307 0.083098 3.469 0.001
L1.Steiermark 0.108730 0.108427 1.003 0.316
L1.Tirol 0.311186 0.087940 3.539 0.000
L1.Vorarlberg 0.026048 0.075835 0.343 0.731
L1.Wien -0.028223 0.140293 -0.201 0.841
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.189004 0.029020 6.513 0.000
L1.Burgenland 0.090149 0.019018 4.740 0.000
L1.Kärnten -0.008911 0.010087 -0.883 0.377
L1.Niederösterreich 0.261344 0.039830 6.561 0.000
L1.Oberösterreich 0.138451 0.038836 3.565 0.000
L1.Salzburg 0.046111 0.020349 2.266 0.023
L1.Steiermark 0.020739 0.026552 0.781 0.435
L1.Tirol 0.093139 0.021535 4.325 0.000
L1.Vorarlberg 0.056169 0.018571 3.025 0.002
L1.Wien 0.114973 0.034356 3.347 0.001
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.111320 0.029532 3.769 0.000
L1.Burgenland 0.045883 0.019354 2.371 0.018
L1.Kärnten -0.014015 0.010265 -1.365 0.172
L1.Niederösterreich 0.188201 0.040533 4.643 0.000
L1.Oberösterreich 0.301518 0.039521 7.629 0.000
L1.Salzburg 0.109695 0.020708 5.297 0.000
L1.Steiermark 0.104623 0.027021 3.872 0.000
L1.Tirol 0.105712 0.021915 4.824 0.000
L1.Vorarlberg 0.068076 0.018899 3.602 0.000
L1.Wien -0.021642 0.034962 -0.619 0.536
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.129892 0.053813 2.414 0.016
L1.Burgenland -0.049786 0.035267 -1.412 0.158
L1.Kärnten -0.040978 0.018705 -2.191 0.028
L1.Niederösterreich 0.164299 0.073858 2.225 0.026
L1.Oberösterreich 0.140567 0.072015 1.952 0.051
L1.Salzburg 0.289332 0.037734 7.668 0.000
L1.Steiermark 0.036441 0.049236 0.740 0.459
L1.Tirol 0.163680 0.039933 4.099 0.000
L1.Vorarlberg 0.099778 0.034437 2.897 0.004
L1.Wien 0.068998 0.063707 1.083 0.279
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.055737 0.042788 1.303 0.193
L1.Burgenland 0.039316 0.028041 1.402 0.161
L1.Kärnten 0.050994 0.014873 3.429 0.001
L1.Niederösterreich 0.217532 0.058726 3.704 0.000
L1.Oberösterreich 0.296514 0.057260 5.178 0.000
L1.Salzburg 0.043672 0.030003 1.456 0.146
L1.Steiermark 0.001119 0.039149 0.029 0.977
L1.Tirol 0.143269 0.031751 4.512 0.000
L1.Vorarlberg 0.072274 0.027381 2.640 0.008
L1.Wien 0.080400 0.050654 1.587 0.112
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.174688 0.051149 3.415 0.001
L1.Burgenland -0.002656 0.033520 -0.079 0.937
L1.Kärnten -0.062753 0.017779 -3.530 0.000
L1.Niederösterreich -0.082806 0.070201 -1.180 0.238
L1.Oberösterreich 0.192042 0.068449 2.806 0.005
L1.Salzburg 0.058337 0.035866 1.627 0.104
L1.Steiermark 0.234903 0.046798 5.019 0.000
L1.Tirol 0.498923 0.037956 13.145 0.000
L1.Vorarlberg 0.045339 0.032731 1.385 0.166
L1.Wien -0.053689 0.060552 -0.887 0.375
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.171930 0.058787 2.925 0.003
L1.Burgenland -0.007615 0.038526 -0.198 0.843
L1.Kärnten 0.066262 0.020434 3.243 0.001
L1.Niederösterreich 0.203723 0.080684 2.525 0.012
L1.Oberösterreich -0.070455 0.078671 -0.896 0.370
L1.Salzburg 0.207711 0.041222 5.039 0.000
L1.Steiermark 0.122566 0.053787 2.279 0.023
L1.Tirol 0.071413 0.043624 1.637 0.102
L1.Vorarlberg 0.117926 0.037619 3.135 0.002
L1.Wien 0.118593 0.069594 1.704 0.088
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.361724 0.033874 10.678 0.000
L1.Burgenland 0.007371 0.022199 0.332 0.740
L1.Kärnten -0.023748 0.011774 -2.017 0.044
L1.Niederösterreich 0.216731 0.046492 4.662 0.000
L1.Oberösterreich 0.198615 0.045331 4.381 0.000
L1.Salzburg 0.043021 0.023753 1.811 0.070
L1.Steiermark -0.013947 0.030993 -0.450 0.653
L1.Tirol 0.105003 0.025137 4.177 0.000
L1.Vorarlberg 0.070232 0.021677 3.240 0.001
L1.Wien 0.037124 0.040102 0.926 0.355
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.039821 0.139806 0.191310 0.151324 0.117467 0.103819 0.062988 0.216352
Kärnten 0.039821 1.000000 -0.006891 0.132818 0.039369 0.094376 0.433538 -0.053559 0.097969
Niederösterreich 0.139806 -0.006891 1.000000 0.334793 0.142379 0.293763 0.095589 0.176962 0.314779
Oberösterreich 0.191310 0.132818 0.334793 1.000000 0.228278 0.324575 0.175447 0.164130 0.261078
Salzburg 0.151324 0.039369 0.142379 0.228278 1.000000 0.142018 0.111718 0.144303 0.124207
Steiermark 0.117467 0.094376 0.293763 0.324575 0.142018 1.000000 0.145734 0.137034 0.070822
Tirol 0.103819 0.433538 0.095589 0.175447 0.111718 0.145734 1.000000 0.111271 0.143110
Vorarlberg 0.062988 -0.053559 0.176962 0.164130 0.144303 0.137034 0.111271 1.000000 -0.001899
Wien 0.216352 0.097969 0.314779 0.261078 0.124207 0.070822 0.143110 -0.001899 1.000000